package page.app.wallet;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

import basicTool.WaitTool;
import io.appium.java_client.AppiumDriver;
import page.app.AbstractAppPage;

public class LendBorrowEarnListPage extends AbstractAppPage {

	@FindBy(xpath = "//UIAStaticText[@name='当前']|//android.widget.Button[@text='当前']")
	private WebElement currentLabel;
	@FindBy(xpath = "//UIAStaticText[@name='已收回']|//android.widget.Button[@text='已收回']")
	private WebElement historyLable;
	@FindBy(xpath = "//UIATableCell[2]|//android.widget.ListView[1]/android.widget.LinearLayout[3]") // 列表中的第一条数据
	private WebElement list;
	@FindBy(xpath = "//UIATableView[contains(@name,'暂无')]|//android.widget.TextView[contains(@text,'暂无')]") // 列表中没有数据
	private WebElement empty;

	public LendBorrowEarnListPage(AppiumDriver appiumDriver) {
		super(appiumDriver);
		WaitTool.waitFor(appiumDriver, ExpectedConditions.visibilityOf(currentLabel), DefaultWaitElementTime4Page);
	}

	public ListToBriefPage ListToBriefPage() throws Exception {
		return click(list, ListToBriefPage.class);
	}

	public ListToBriefPage CurrentToHistoryPage() throws Exception {
		return click(historyLable, ListToBriefPage.class);
	}

	public ListToBriefPage HistoryToCurrent() throws Exception {
		return click(currentLabel, ListToBriefPage.class);
	}

	public <Page extends AbstractAppPage> Page TabSwitch() throws Exception {
		if (isDisplayed(empty)) {
			click(historyLable, LendBorrowEarnListPage.class);
			if (isDisplayed(empty))
				return (Page) this;
		}
		return null;
	}

}
